#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
import pymysql

# 打开数据库连接
db = pymysql.connect("localhost", "root",
    '', 'bilibili')

# 使用cursor()方法获取操作游标 
cursor = db.cursor()

# SQL 查询语句
# sql0 = """create table xinji(name char(10), sex tinyint(1));
# """
sql1 = "SELECT * FROM upzhu;"
sql2 = "insert into upzhu values (%s, %s, %s);"

try:
    # 执行SQL语句
    # cursor.execute(sql1)
    cursor.execute(sql2, ('老邪', 0, 0))
    cursor.execute(sql1)
    # 获取所有记录列表
    results = cursor.fetchall()
    for row in results:
        name, video, followed = row
        # 打印结果
        print("name:%s, video:%d, followed:%s" %
             (name, video, followed))
except:
    print("Error: unable to fetch data")

# 关闭数据库连接
db.close()
